@extends('layouts.app')

@section('title', '产品')

@section('header')
    @include('layouts.header-two')
@stop

@section('style')
    <style>
        .pagination>.active>span {background-color: #D33829; border-color: #D33829}
        .pagination>.active>span:hover {background-color: #D33829; border-color: #D33829}
        .pagination > li > a, .pagination > li > span { color:#444}
    </style>
@stop

@section('content')
<div class="search-bar">
    <div class="container">
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <form>
                    <div class="input-group">
                        <input name="keyword" type="text" class="form-control" placeholder="请输入你要搜索的书名" value="{{ isset($param['keyword']) ? $param['keyword'] : '' }}">
                        <span class="input-group-btn">
                            <button class="btn search" type="submit">搜索</button>
                        </span>
                    </div>
                    {!! csrf_field() !!}
                </form>
            </div>
        </div>
    </div>
</div>
<div class="search-section">
    <div class="container">
        <div class="search-section-wrapper">
            <div class="row">
                <div class="col-md-2">
                    <div class="search-section-ls">
                        <h2>产品分类</h2>
                        <div class="search-sidebar">
                            @foreach($categorys as $category)
                            <div class="sidebar-section">
                                @if(count($category->children) <= 0)
                                    <a href="{{ route('productIndex', ['category_id' => $category->id, 'keyword' => isset($param['keyword']) ? $param['keyword'] : '']) }}"><h3>{{ $category->name }}</h3></a>
                                @else
                                    <h3>{{ $category->name }}</h3>
                                @endif
                                <ul>
                                    @foreach($category->children as $child)
                                        <li @if($categoryId == $child->id) class="ons" @endif>
                                            <a href="{{ route('productIndex', ['category_id' => $child->id, 'keyword' => isset($param['keyword']) ? $param['keyword'] : '']) }}">{{ $child->name }}</a>
                                        </li>
                                    @endforeach
                                </ul>
                            </div>
                            @endforeach
                        </div>
                    </div>
                </div>
                <div class="col-md-10">
                    <div class="search-section-rs">
                        @if($filter)
                        <div class="search-cate">
                            @foreach($filter as $key => $value)

                                @if(count($value->children) > 0)
                                <div class="cate_detail_item">
                                    @if($specialFilter)
                                        <a class="cate_detail_tit">分类：</a>
                                    @else
                                        <a href="{{ route('productIndex',array_merge($param, ['L' => $value->id])) }}" class="cate_detail_tit">{{ $value->name }}：</a>
                                    @endif
{{--                                    {{ dd($specialFilter, $value->toArray()) }}--}}
                                    @foreach($value->children as $k => $child)
                                        <a href="{{ route('productIndex', ['category_id' => $categoryId, 'C' => $param['C'] . ',' . $child->id, 'keyword' => isset($param['keyword']) ? $param['keyword'] : '']) }}"
                                           class="cate_detail_con @if(in_array($child->id, $selectArr)) actives @endif">
                                            {{ $child->name }}
                                        </a>
                                    @endforeach
                                </div>
                                @endif
                                @if(isset($value->grades))
                                    <div class="cate_detail_item">
                                        <a class="cate_detail_tit">年级：</a>
                                        @foreach($value->grades as $k => $grade)
                                            <a href="{{ route('productIndex', ['category_id' => $categoryId, 'C' => $param['C'] . ',' . $grade->id, 'keyword' => isset($param['keyword']) ? $param['keyword'] : '']) }}"
                                               class="cate_detail_con @if(in_array($grade->id, $selectArr)) actives @endif">
                                                {{ $grade->name }}
                                            </a>
                                        @endforeach
                                    </div>
                                @endif
                            @endforeach
                        </div>
                        @endif
                        <div class="deep-search">
                            <span class="deep-search-tit">精准过滤：</span>
                            <div class="s-feature">
                                <ul>
                                    @foreach($resources as $resource)
                                        <li>
                                            <a @if(isset($param['resource_id']) && $param['resource_id'] == $resource->id) class="selected" @endif
                                                href="
                                                    @if (isset($param['resource_id']) && $param['resource_id'] == $resource->id)
                                                        {{ route('productIndex', array_merge($param, ['resource_id' => ''])) }}
                                                    @else
                                                        {{ route('productIndex', array_merge($param, ['resource_id' => $resource->id])) }}
                                                    @endif
                                                ">
                                                <i></i>
                                                {{ $resource->name }}
                                            </a>
                                        </li>
                                    @endforeach
                                </ul>
                            </div>
                        </div>
                        <div class="deep-search">
                            <span class="deep-search-tit">排序：</span>
                            <div class="s-feature">
                                <ul>
                                    <li>
                                        <a @if(isset($param['order']) && $param['order'] == 'push') class="selected" @endif
                                        href="{{ route('productIndex', array_merge($param, ['order' => 'push'])) }}">
                                            <i></i>
                                            出版时间
                                        </a>
                                    </li>
                                    <li>
                                        <a @if(isset($param['order']) && $param['order'] == 'created') class="selected" @endif
                                        href="{{ route('productIndex', array_merge($param, ['order' => 'created'])) }}">
                                            <i></i>
                                            上传时间
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <div class="search-tab">
                            <ul class="search-warp clearfix">
                                @foreach($products as $key => $product)
                                <li class="search-item">
                                    <div class="search-i-wrap">
                                        <a target="_blank" href="{{ route('productInfo', ['uuid' => $product->uuid]) }}">
                                            <div class="search_item_img">
                                                <img originalSrc="@if($product->cover){{ asset('uploads/' . $product->cover[0]) }} @endif" alt="" />
                                            </div>
                                            <p>{{ $product->name }}</p>
                                            <div class="search-i-bt clearfix">
                                                @if($product->buy_switch == 1)
                                                    <div class="buy-btn"><a target="_blank" href="{{ $product->buy_link }}" style="color: white;">点击购买</a></div>
                                                @endif
                                            </div>
                                        </a>
                                    </div>
                                </li>
                                @endforeach
                            </ul>
                            <div class="page">
                                {!! $products->appends($param)->render() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@stop

@section('footer')
    @include('layouts.footer')
@stop

@section('script')
<script type="text/javascript" src="{{ asset('statics/js/lyz.delayLoading.min.js') }}" ></script>
<script>
    $(".sidebar-section").eq(1).find("h3").css({"background-position":"0px -147px"});
    $(".sidebar-section").eq(2).find("h3").css({"background-position":"0px -184px"});

    $(function(){
        var h1=$(".search-section-rs").height();
        var h2=$(".search-section-ls").height();
        if(h1>h2){
            $(".search-section-ls").height($(".search-section-rs").height());
        }
    })

    //--------------------图片延迟加载--------------------//
    $(function () {
        $(".search_item_img img").delayLoading({
            defaultImg: "statics/images/loadings.gif",
            errorImg: "",
            imgSrcAttr: "originalSrc",
            beforehand: 0,
            event: "scroll",
            duration: "normal",
            container: window,
            success: function (imgObj) { },
            error: function (imgObj) { }
        });
    });
</script>
@stop